package redis

import (
	"fmt"

	"github.com/go-redis/redis"
	"github.com/spf13/viper"
)

var Client *redis.Client
// docker exec -it my-redis redis-cli
func Init() (err error) {
	Client = redis.NewClient(&redis.Options{
		Addr: fmt.Sprintf("%s:%d",
			viper.GetString("redis.host"),
			viper.GetInt("redis.port"),
		),
		Password: viper.GetString("redis.password"), // 密码
		DB:       viper.GetInt("reids.db"),          // 使用第 0 个数据库
		PoolSize: viper.GetInt("redis.pool_size"),
	})
	_, err = Client.Ping().Result()
	return
}

func Close() {
	_ = Client.Close()
}
